#include<iostream>
#include<queue>
using namespace std;
int n,a,b,a_[50001]={0};
typedef struct x{
	int a,b;
	x(int a,int b):a(a),b(b){}
}x;
void bfs();
int main(){
	cin>>n>>a>>b;
	bfs();
	return 0;
}
void bfs(){
	queue<x>q;
	q.push(x(a,0));
	while(!q.empty()){
		x p=q.front();
		if(p.a==b){
			cout<<p.b;
			return;
		}
		q.pop();
		for(int i=-1;i<2;i+=2){
			int ta=p.a+i;
			if(ta>0&&ta<=n&&!a_[ta]){
				q.push(x(ta,p.b+1));
				a_[ta]=1;
			}
		}
		int ta=p.a*2;
		if(ta<=n&&!a_[ta]){
			q.push(x(ta,p.b+1));
			a_[ta]=1;
		}
	}
}